package wnhz.com.business.rebateshop.activity.mine;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.WindowManager;

import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import wnhz.com.business.R;
import wnhz.com.business.base.BaseActivity;
import wnhz.com.business.impl.ActionBarClickListener;
import wnhz.com.business.uitls.LogUtils;
import wnhz.com.business.view.TranslucentActionBar;

public class AllOrderActivity extends BaseActivity implements ActionBarClickListener {

    @BindView(R.id.tl_3)
    SlidingTabLayout tl_3;
    @BindView(R.id.actionbar)
    TranslucentActionBar actionbar;
    @BindView(R.id.vp)
    ViewPager vp;

    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private final String[] mTitles = {"全部", "待付款", "待发货", "待收货", "待评价", "退款/售后"};
    private MyPagerAdapter mAdapter;
    private String type;

    public static Intent createIntent(Context context, String type) {
        Intent intent = new Intent(context, AllOrderActivity.class);
        intent.putExtra("type", type);
        return intent;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_all_order);
        ButterKnife.bind(this);
        type = getIntent().getStringExtra("type");
        actionbar.setData("全部订单", R.drawable.ic_lefft_white, null, 0, null, 0, this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            actionbar.setStatusBarHeight(getStatusBarHeight());
        }

        mFragments.add(OrderAllFragment.getInstance());
        mFragments.add(OrderOneFragment.getInstance());
        mFragments.add(OrderTwoFragment.getInstance());
        mFragments.add(OrderThreeFragment.getInstance());
        mFragments.add(OrderFourFragment.getInstance());
        mFragments.add(OrderFifthFragment.getInstance());

        mAdapter = new MyPagerAdapter(getSupportFragmentManager());
        vp.setAdapter(mAdapter);

        tl_3.setViewPager(vp, mTitles, this, mFragments);

        tl_3.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                LogUtils.e("onTabSelect&position--->", "  ===  " + position);
                vp.setCurrentItem(position);
            }

            @Override
            public void onTabReselect(int position) {
                LogUtils.e("onTabReselect&position--->", "  ===  " + position);
            }
        });

        vp.setCurrentItem(Integer.valueOf(type));
    }

    @Override
    public void onLeftClick() {
        finish();
    }

    @Override
    public void onRightClick() {

    }

    @Override
    public void onEditTextClick() {

    }

    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }
}
